﻿using System.Collections.Generic;
using System.Linq;
using studentSubsidy.Models;
using studentSubsidy.Utils;

namespace studentSubsidy.Dao
{
    public class FinancialDao
    {
        private MyDbContext DbContext = new MyDbContext();

        public List<Apply> getNeedToPayment(int userId)
        {
            return DbContext.Applies.Where(p => p.user_id == userId && p.isCheck == 1 && p.isPayment == 0).ToList();
        }

        public List<Apply> getHasPaymentList(int userId)
        {
            return DbContext.Applies.Where(p => p.user_id == userId && p.isPayment == 1).ToList();
        }

        public List<Apply> getNeedDueList(int userId)
        {
            return DbContext.Applies.Where(p => p.isPayment == 1 && p.isSigned == 1 && p.user_id == userId).ToList();
        }

        public Refund_Log getRefundLogById(int id)
        {
            return DbContext.RefundLogs.Where(p => p.id == id).ToList().First();
        }

        public void updateRefundLogState(Refund_Log refundLog)
        {
            DbContext.RefundLogs.Update(refundLog);
            DbContext.SaveChanges();
        }

        public Refund getRefundById(int id)
        {
            return DbContext.Refund.Where(p => p.id == id).ToList().First();
        }
        
    }
}